package com.lianzhihui.romeex.widget;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;


import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.ui.base.BaseDialog;
import com.lianzhihui.romeex.utils.LogUtil;

import butterknife.BindView;

/**
 * Copyright (C), 2019-2019, wase_five
 * FileName: CurrencyTypeDialog
 * Author: echo
 * Date: 2019/11/4 18:44
 * Description: 转账，分裂弹窗
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
public class LoadingDialog extends BaseDialog {
    @BindView(R.id.tv_title)
    TextView tv_title;

    public LoadingDialog(@NonNull Activity activity) {
        super(activity);
    }

    public LoadingDialog(@NonNull Context activity) {
        super(activity);
    }

    @Override
    protected int provideViewId() {
        return R.layout.dialog_loading;
    }

    @Override
    protected void initView() {
        setCanceledOnTouchOutside(false);
        setCancelable(false);
    }

    public void setTitle(String title) {
        if (TextUtils.isEmpty(title)) {
            tv_title.setVisibility(View.GONE);
        } else {
            tv_title.setVisibility(View.VISIBLE);
        }
        tv_title.setText(title);
    }

    Handler handler;
    Runnable disRb;

    @Override
    public void show() {
        super.show();
        if (this.context != null && !((Activity) this.context).isDestroyed()) {
            try {
                handler = new Handler();
                disRb = new Runnable() {
                    @Override
                    public void run() {
                        if (context != null) {
                            dismiss();
                        }
                    }
                };
                handler.postDelayed(disRb, 10 * 1000);
            } catch (Exception e) {
                LogUtil.error("loadingDialog:", e.getMessage());
            }
        }

    }

}
